﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.m
{
    /// <summary>
    /// photo_list 的摘要说明
    /// </summary>
    public class photo_category : IHttpHandler, IRequiresSessionState
    {
        protected int totalCount = 0;
        protected int page = 1;
        protected int pageSize = 0;
        public void ProcessRequest(HttpContext context)
        {
          

            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            //材质
            BLL.caizhi bll = new BLL.caizhi();
            DataTable dt = bll.GetList(0, "", "sort_id asc,id desc").Tables[0];
            //如果记录存在
            if (dt.Rows.Count > 0)
            {
                strTxt.Append("\"caizhi_list\":[");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < dt.Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("],");
            }
            else
            {
                strTxt.Append("\"caizhi_list\":[],");
            }


            //纹理
            BLL.wenli bll_wenli = new BLL.wenli();
            DataTable dt_wenli = bll_wenli.GetList(0, "", "sort_id asc,id desc").Tables[0];
            //如果记录存在
            if (dt_wenli.Rows.Count > 0)
            {
                strTxt.Append("\"wenli_list\":[");
                for (int i = 0; i < dt_wenli.Rows.Count; i++)
                {
                    DataRow dr = dt_wenli.Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < dt_wenli.Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("],");
            }
            else
            {
                strTxt.Append("\"wenli_list\":[],");
            }



            //用途
            BLL.yongtu bll_yongtu = new BLL.yongtu();
            DataTable dt_yongtu = bll_yongtu.GetList(0, "", "sort_id asc,id desc").Tables[0];
            //如果记录存在
            if (dt_yongtu.Rows.Count > 0)
            {
                strTxt.Append("\"yongtu_list\":[");
                for (int i = 0; i < dt_yongtu.Rows.Count; i++)
                {
                    DataRow dr = dt_yongtu.Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < dt_yongtu.Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("],");
            }
            else
            {
                strTxt.Append("\"yongtu_list\":[],");
            }


            //颜色
            BLL.yanse bll_yanse = new BLL.yanse();
            DataTable dt_yanse = bll_yanse.GetList(0, "", "sort_id asc,id desc").Tables[0];
            //如果记录存在
            if (dt_yanse.Rows.Count > 0)
            {
                strTxt.Append("\"color_list\":[");
                for (int i = 0; i < dt_yanse.Rows.Count; i++)
                {
                    DataRow dr = dt_yanse.Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < dt_yanse.Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                strTxt.Append("\"color_list\":[]");
            }





            strTxt.Append("}");

            context.Response.Write(strTxt.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}